Imports System.IO
Imports System.Drawing
Imports MIMS.WRS.Business

Public Class ViewPicture
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim size As Integer = -1
        If (Request("size") <> Nothing) Then
            size = Integer.Parse(Request("size"))
        End If
        Response.Clear()

        Dim proCode As String = Request("procode")

        Dim filePath As String = String.Format("{0}.jpg", Path.Combine(Config.ProductImagePath, proCode))

        If File.Exists(filePath) Then
            Dim buff() As Byte
            If (size > 0) Then
                buff = ImageService.GenerateSquareThumbnail(Image.FromFile(filePath), size)
            Else
                Dim fi As FileInfo = New FileInfo(filePath)
                Dim fs As FileStream = File.OpenRead(filePath)
                ReDim buff(Convert.ToInt32(fi.Length))
                fs.Read(buff, 0, buff.Length)
                fs.Close()
            End If                        
            Response.BinaryWrite(buff)
        End If

        Response.End()
    End Sub

End Class
